import re
import requests
import os
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'
}

os.mkdir('./picture')#创建图片文件夹
num = int(input("想获取几页呢："))
for i in range(1,num+1):#num为想获取页数
    url = 'https://www.qiushibaike.com/imgrank/page/%s/' % i
    page = requests.get(url,headers).text
    # print(page)
    result = re.findall('<img src="(.*\.jpg)"',page)
    # print(result)
    for i in result:
        i = 'https:' + i
        img = requests.get(url=i, headers=headers).content
        img_name = i.split('/')[-1]
        img_path = './picture/' + img_name
        print(i,'爬取成功')
        with open(img_path,'wb') as f:
            f.write(img)

